package hibernate;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import model.IAlbum;
import model.IArtist;
import model.ISong;

import org.hibernate.annotations.Proxy;

/**
 * @author ipeel
 *
 */
@Entity
@Table (name="album")
@Proxy(proxyClass=IAlbum.class)
public class Album implements IAlbum {
	
	@Id	
	@GeneratedValue(strategy=GenerationType.AUTO) 
	@Column(name="album_id")
	private Integer id;
	
	@ManyToOne(fetch=FetchType.LAZY, targetEntity=Artist.class)
	@JoinColumn(name="artist_id", insertable=false, updatable=false)
	private IArtist artist;
	
	@Column(name="name")
	private String name;
	
	@OneToMany(targetEntity=Song.class, cascade=CascadeType.ALL)
	@JoinColumn(name="album_id")
	private Set<ISong> songs = new HashSet<ISong>();
	
	public IArtist getArtist() {
		return artist;
	}
	public void setArtist(IArtist artist) {
		this.artist = artist;
	}

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public void addSong(ISong song) {		
		songs.add(song);
	}
	
	public Set<ISong> getSongs() {
		return songs;
	}
	
	public void setSongs(Set<ISong> songs) {
		this.songs = songs;
	}
	/* (non-Javadoc)
	 * @see model.IAlbum#getTrackCount()
	 */
	public Integer getTrackCount() {
		return songs.size();
	} 
}
